import { applyMiddleware, createStore, compose } from "redux";
import thunk from "redux-thunk";
import { combineReducers } from 'redux'

// 导入子reducer
import counter from './reducers/user'
import cart from './reducers/cart'
import { persistStore, persistReducer } from 'redux-persist'
import storage from 'redux-persist/lib/storage'

const rootReducer = combineReducers({
    counter,
    cart
})
const persistConfig = {
    key: 'root',
    storage,
    whiteList:['counter','cart']
}
const myPersistReducer = persistReducer(persistConfig, rootReducer)
const composeEnhancers = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
const store = createStore(myPersistReducer, composeEnhancers(applyMiddleware(thunk)))
const persistor = persistStore(store)

export {persistor,store}
export default store